const express=require('express');
const router=express.Router();

const bodyParser=require('body-Parser');
router.use(bodyParser.urlencoded({extended:false}));

const fs=require('fs');


router.get('/abc',(req,res)=>{
    let id=req.query.id;
    res.sendFile(__dirname+'/data/'+id+'.json')
});
router.post('/abc',(req,res)=>{
    let data=req.body.getobj;
    fs.writeFile(__dirname+'/data/stu.json',data,()=>{
        res.send('成功');
    })
});

router.get('/s2',(req,res)=>{
    res.send(`${req.query.cd}({username:"yanghandong",age:21,sex:"boy"})`)
})

// 资源共享
const cors=require('cors');
router.use(cors({
    origin:'http://106.12.24.181:4019',
    credentials:true
}));
router.get('/home',cors(),(req,res)=>{
    let id=req.query.id;
    res.sendFile(__dirname+'/data/'+id+'.json')
})
module.exports=router;